{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 7-3. Getting Started with Real-World Robots - Record your Dataset and Visualize it\n",
    "\n",
    ":::{note}\n",
    "\n",
    "This notebook content is derived from lerobot repo's example note \"[7_get_started_with_real_robot.md](https://github.com/huggingface/lerobot/blob/main/examples/7_get_started_with_real_robot.md#3-record-your-dataset-and-visualize-it)\".\n",
    "\n",
    "The notebook is formated in Jupyter notebook style, so that one can just follow this notebook on Jetson (running Jupyer Lab server inside the lerobot container).\n",
    "\n",
    "Please note that this notebook (along with other in the series) may not be the full copy of the original note, as it tries to catpure the essense and important part that involves with Python code executions.<br>\n",
    "For the full documentation and its update, please always refer to the original document (\"[7_get_started_with_real_robot.md](https://github.com/huggingface/lerobot/blob/main/examples/7_get_started_with_real_robot.md)\").\n",
    "\n",
    ":::"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## a. Use `koch.yaml` and the `record` function"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    ":::{note}\n",
    "\n",
    "Before trying `record`, if you want to push your dataset to the hub, make sure you've logged in using a write-access token, which can be generated from the [Hugging Face settings](https://huggingface.co/settings/tokens):\n",
    "```bash\n",
    "huggingface-cli login --token ${HUGGINGFACE_TOKEN} --add-to-git-credential\n",
    "```\n",
    "Also, store your Hugging Face repository name in a variable (e.g. `cadene` or `lerobot`). For instance, run this to use your Hugging Face user name as repository:\n",
    "```bash\n",
    "HF_USER=$(huggingface-cli whoami | head -n 1)\n",
    "echo $HF_USER\n",
    "```\n",
    "If you don't want to push to hub, use `--push-to-hub 0`.\n",
    "\n",
    ":::"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now run the following in the terminal to record 2 episodes:\n",
    "\n",
    "```\n",
    "python lerobot/scripts/control_robot.py record \\\n",
    "  --robot-path lerobot/configs/robot/koch.yaml \\\n",
    "  --fps 30 \\\n",
    "  --root data \\\n",
    "  --repo-id ${HF_USER}/koch_test \\\n",
    "  --tags tutorial \\\n",
    "  --warmup-time-s 5 \\\n",
    "  --episode-time-s 30 \\\n",
    "  --reset-time-s 30 \\\n",
    "  --num-episodes 2 \\\n",
    "  --push-to-hub 0 \\\n",
    "  --run-compute-stats 1\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## b. Advices for recording dataset\n",
    "\n",
    "## c. Visualize all episodes\n",
    "\n",
    "Run the following to visualize recorded data.\n",
    "\n",
    "```bash\n",
    "python lerobot/scripts/visualize_dataset_html.py \\\n",
    "  --root data \\\n",
    "  --repo-id ${HF_USER}/koch_test\n",
    "```\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## d. Replay episode on your robot with the `replay` function\n",
    "\n",
    "```bash\n",
    "python lerobot/scripts/control_robot.py replay \\\n",
    "  --robot-path lerobot/configs/robot/koch.yaml \\\n",
    "  --fps 30 \\\n",
    "  --root data \\\n",
    "  --repo-id ${HF_USER}/koch_test \\\n",
    "  --episode 0\n",
    "```\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
